<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>设置支付密码</title>
    <link rel="stylesheet" href="__CSS__/login_register.css">
</head>
<body style="margin: 0;padding: 0;background-color: #f3f3f3;">
<div class="topbar-between gradient-color horizontal-view">
<!--  -->
    <div class="topbar-back" onclick="location.href='<if condition="$_GET['ref']">{$ref}<else/>/Wx/Login/userInfo</if>'"><div class="topbar-back-icon"></div></div>
    <div class="topbar-title">设置支付密码</div>
    <div style="width: 2.5rem;"></div>
</div>
<!--<div class="horizontal-view binding-input-wrap">
    <div class="text-content text-gray">当前密码：</div>
    <input class="binding-input" type="password" placeholder=""/>
</div>-->
<div class="horizontal-view binding-input-wrap" style="margin-top: 1px">
    <div class="text-content text-gray">新密码：</div>
    <input class="binding-input" type="password" name="" placeholder="请输入6位数字密码" id="newpwd" maxlength="6"/>
</div>
<div class="horizontal-view binding-input-wrap" style="margin-top: 1px">
    <div class="text-content text-gray">确认新密码：</div>
    <input class="binding-input" type="password" placeholder="请再次确认6位数字密码" id="rnewpwd" maxlength="6"/>
</div>
<!--<div class="forget-btn text-blue">忘记当前密码？</div>-->
<div class="button-simple button-simple-color" onclick="save()">确认</div>
<input type="hidden" id="isrepeat" value="0"/>
<script src="__JS__/jquery2.1.1.min.js"></script>
<script src="__JS__/layer.min.js"></script>
<script>
    function save() {
        if($('#isrepeat').val()==1){
            layer.msg('请不要重复提交');
            return;
        }
        var url = "/Wx/Login/setPayPwd";
        var newpwd=$.trim($('#newpwd').val());
        var rewpwd=$.trim($('#rnewpwd').val());
        var re = /^\d+$/;
        if(!re.test(newpwd)){
            layer.msg('密码只能是数字');
            return;
        }


        if(newpwd==''||newpwd.length<6||newpwd.length>10){
            layer.msg('密码格式不正确（6位数字）');
            return;
        }
        if(rewpwd!=newpwd){
            layer.msg('重复密码不正确');
            return;
        }
        $('#isrepeat').val(1);
        $.ajax({
            type : "POST",
            url : url,
            data : {
                newpwd:newpwd
            },
            dataType : "json",
            success : function(data) {
                $('#isrepeat').val(0);
                if(data.status==-2){
                    layer.msg('非法请求');
                    return;
                }else if(data.status==0){
                    layer.msg('密码设置成功');
                    setTimeout(function(){
                        var url = '/Wx/Login/userInfo';
                        <if condition="$_GET['ref']">
                            url = '{$_GET['ref']}';
                        </if>
                        location.href=url;
                    },2000);

                    return;
                }else{
                    layer.msg('密码设置失败');
                    return;
                }
            }
        });
    }
</script>
</body>
</html>